function echo<T>(arg: T): T {
    return arg
}
const str: string = 'str'

const result = echo(true)


function swap<T, U>(tuple: [T, U]): [U, T] {
    return [tuple[1], tuple[0]]
}

const result2 = swap(['string', 123])


// 约束泛型
function echoWithArr<T>(arg: T[]): T[] {
    console.log(arg.length);
    return arg
}

const arrs = echoWithArr([1, 2, 3])

interface IwithLength {
    length: number
}

function echoWithArrLength<T extends IwithLength>(arg: T): T {
    console.log(arg.length);
    return arg
}

const str1 = echoWithArrLength('str')
let arr2 = echoWithArrLength({ length: 2 })

// class Queue {
//     private data = []
//     push(item){
//         return this.data.push(item)
//     }
//     pop(item){
//         return this.data.pop(item)
//     }
// }
let a: number[] = [1, 2, 3, 4, 5]
console.log('====================================');
console.log(a.slice(0, 2));
console.log(a);
console.log('====================================');


interface IPlus<T> {
    (a: T, b: T): T
}
function plus(a: number, b: number): number {
    return a + b
}

const c: IPlus<number> = plus